﻿using System;
using Cairo;
using Gtk;
using System.Drawing;
//using Graphics = System.Drawing.Graphics;

namespace GTKTest
{
    //class Program
    //{
    //    static void Main(string[] args)
    //    {
    //        Application.Init();
    //        Window myWindow = new Window("This is a window");
    //        myWindow.DeleteEvent += OnDelete;
    //        myWindow.SetDefaultSize(200, 200);

    //        //Put a button in the Window
    //        Button button = new Button("Click");
    //        button.Clicked += (s, e) => Console.WriteLine("hello world");
    //        myWindow.Add(button);
    //        myWindow.ShowAll();
    //        Application.Run();
    //    }
    //    static void OnDelete(object o, DeleteEventArgs e)
    //    {
    //        Application.Quit();
    //    }
    //}
    class Program
    {
        //static void Main(string[] args)
        //{
        //    Application.Init();
        //    Window myWindow = new Window("This is a window");
        //    //myWindow.DeleteEvent += OnDelete;
        //    myWindow.SetDefaultSize(500, 500);
        //    //VBox vbox1 = new VBox();
        //    //VBox vbox2 = new VBox();
        //    //GdkGC
        //    //Drawable 
        //    Gtk.DrawingArea drawingArea = new DrawingArea();
        //    //Context cr = new Context();
        //    //Gtk.Widget w = new Widget();
        //    //drawingArea.c
        //    Button button1 = new Button("Click");
        //    TextView textView = new TextView();
        //    button1.SetSizeRequest(30,30);
        //    //Label label = new Label("say hello!");

        //    myWindow.Add(button1);
        //    //myWindow.Add(label);
        //    //vbox1.Add(button1);
        //    //vbox2.Add(label);
        //    //Button button2 = new Button();
        //    button1.Clicked += (s, e) => Console.WriteLine("hello world");


        //    //myWindow.Add(vbox1);
        //    //myWindow.Add(vbox2);
        //    myWindow.ShowAll();
        //    //vbox1.Show();
        //    //vbox2.Show();
        //    Application.Run();
        //}
        static void Main(string[] args)
        {
            Application.Init();
            Window myWindow = new Window("This is a window");
            myWindow.SetDefaultSize(500, 500);
           // Gtk.DrawingArea drawingArea = new DrawingArea();
            myWindow.ShowAll();
            OnPaint();
            Application.Run();
        }
       // protected override void OnPaint(PaintEventArgs e)
            public static void OnPaint()
        {
            const double pi = 3.1415927;
            Gtk.DrawingArea drawingArea = new DrawingArea();
            
            //base.OnPaint(e);
            //using (System.Drawing.Graphics graphics = e.Graphics)
            //{
           //using (Win32Surface surface = new Win32Surface(graphics.GetHdc()))
           // using (Surface surface = new ImageSurface(Format.Argb32, 500, 500))
            using (Win32Surface surface = new Win32Surface(drawingArea.Handle))
            // using (Surface surface = new Surface())
            {
                using (Context context = new Context(surface))
                {
                    context.LineWidth = 2.0;
                    //context.SetSourceRGBA(0.95294117647058818, 0.6, 0.0784313725490196, 1.0);
                    context.SetSourceRGB(0, 0, 0);//CK:画笔颜色

                    //context.SetSourceColor(this.bugColor);
                    context.MoveTo(7.0, 64.0);
                    context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0);
                    context.MoveTo(25.0, 80.0);
                    context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0);
                    context.MoveTo(10.0, 41.0);
                    context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0);
                    ////context.LineWidth = 2.0;
                    context.MoveTo(1.0, 26.0);
                    context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0);
                    context.LineTo(12.0, 14.0);
                    ////context.Stroke();
                    context.MoveTo(30.0, 74.0);
                    context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0);
                    context.LineTo(10.0, 45.0);
                    context.LineTo(10.0, 40.0);
                    context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0);
                    context.Stroke();
                    // context.MoveTo(50.0, 50.0);
                    context.Arc(100.0, 100.0, 30.0, 0.0, 2 * pi);
                    context.Stroke();
                    context.Rectangle(100.0, 40, 30, 60);
                    context.Stroke();
                }
            }
            //}
        }
        //public void DrawPic()
        //{
        //    //gtk_widget_set_app_paintable
        //    //gdk.draw_rectangle(canvas, gc, FALSE, 0, 0, w, h);
        //    Graphics g1 = pictureBox1.CreateGraphics();
        //    g1.Clear(Color.White);
        //    Pen p = new Pen(Color.Red, 2);//画笔
        //    Pen p1 = new Pen(Color.Black, 2);
        //    Pen p2 = new Pen(Color.Brown, 5);
        //    Pen p3 = new Pen(Color.Black, 20);
        //    Font f = new Font("宋体", 10);//字体
        //    int a = pictureBox1.Size.Height;
        //    int b = pictureBox1.Size.Width;
        //    g1.DrawLine(p1, 0, a, 0, 0);//画线
        //    g1.DrawLine(p1, 0, a, b, a);
        //    g1.DrawLine(p1, 0, 0, 5, 10);
        //    g1.DrawLine(p1, b, a, b - 10, a - 5);
        //    g1.DrawString("O", f, Brushes.Black, 3, a - 20);
        //    g1.DrawString("正北X", f, Brushes.Black, 3, 3);
        //    g1.DrawString("正东Y", f, Brushes.Black, b - 50, a - 20);

        //}
    }

}
